package com.hspedu.newData.dmsxl.数组;

import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-10 
 * @Version: 1.0
 */

public class LC1534统计好三元组 {

    // todo 优化
    public int countGoodTriplets(int[] arr, int a, int b, int c) {

        int n = arr.length, cnt = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                for (int k = j + 1; k < n; ++k) {
                    if (Math.abs(arr[i] - arr[j]) <= a && Math.abs(arr[j] - arr[k]) <= b && Math.abs(arr[i] - arr[k]) <= c) {
                        ++cnt;
                    }
                }
            }
        }
        return cnt;
    }


    @Test
    public void test() {
        // 测试代码

        int a = countGoodTriplets(new int[]{3,0,1,1,9,7},7,2,3);
        int b = countGoodTriplets(new int[]{1,1,2,2,3},0,0,1);
        System.out.println("111");
    }

}
